//
//  DetailsToolBar.m
//  LoveLove
//
//  Created by leiyifan on 2019/5/27.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "DetailsToolBar.h"


@interface DetailsToolBar()

@property (nonatomic,strong) NSArray *buttonArray;

@end

@implementation DetailsToolBar

-(NSArray *)buttonArray{
    if (!_buttonArray) {
        _buttonArray = [NSArray array];
    }
    return _buttonArray;
}


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        NSArray *iconArr = @[@"dialogue",@"heart",@"share"];
        NSArray *textArr = @[@"评论",@"点赞",@"分享"];
        NSMutableArray *buttonArr = [NSMutableArray array];
        for (int i  = 0; i < 3; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [self addSubview:button];
            button.frame = CGRectMake(LLScreenWidth/3*i, 0, LLScreenWidth/3, 40);
//            button.backgroundColor = [UIColor redColor];
            [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -20, 0.0, 0.0)];
            [button setImage:[UIImage imageNamed:iconArr[i]] forState:UIControlStateNormal];
            [button setTitle:textArr[i] forState:UIControlStateNormal];
            [button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:12];
            [buttonArr addObject:button];
            [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = 200+i;
        }
        self.buttonArray = buttonArr;
    }
    return self;
}

- (void) update:(NSArray *)array;
{
    for (int i  = 0; i < 3; i++) {

        UIButton *button = [self viewWithTag:200+i];
        if ([array[i] intValue] != 0) {

            [button setTitle:array[i] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithRed:227/255.0 green:15/255.0 blue:29/255.0 alpha:1] forState:UIControlStateNormal];
        }
    }
}

-(void)clickButton:(UIButton *)button{
    button.selected = !button.selected;
    NSInteger type = button.tag - 200;
    if (self.toolBarBlock) {
        self.toolBarBlock(type,button.selected);
    }
}

@end
